package ooday04;

public class Test {
    public static void main(String[] args) {

        Master master = new Master();
        Dog dogs = new Dog("小狗", 1, "绿色");
        Fish fish = new Fish("小狗", 2, "紫色");
        Chick chicks = new Chick("小狗", 3, "白色");
        master.feed(fish);
        master.feed(dogs);
        master.feed(chicks);


        Animal[] animals = new Animal[6];
        animals[0] = new Dog("小狗", 1, "绿色");
        animals[1] = new Dog("小狗", 2, "紫色");
        animals[2] = new Fish("小鱼", 3, "白色");
        animals[3] = new Fish("小鱼", 4, "橙色");
        animals[4] = new Chick("小鸡", 5, "橘色");
        animals[5] = new Chick("小鸡", 6, "黄色");
        for (int i = 0; i < animals.length ; i++) {//遍历所以动物
            System.out.println(animals[i].name);//输出所有动物名字
            animals[i].eat();//所有动物吃饭
            animals[i].drink();//所有动物喝水
            if (animals[i] instanceof Dog){//dog类型
                Dog dog = (Dog) animals[i];
                dog.lookAfterTheHouse();
            }if (animals[i] instanceof Chick){//chick类型
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }if(animals[i] instanceof Swim){//若能游泳
                Swim swims = (Swim) animals[i];
                swims.swim();
            }
        }
    }
}
